#include <metahook.h>
#include <vgui/IEngineVGui.h>

#include <vgui_controls/Controls.h>
#include <vgui_controls/Frame.h>
#include <vgui_controls/Button.h>
#include <vgui_controls/Label.h>
#include <vgui_controls/CheckButton.h>
#include <vgui_controls/RadioButton.h>
#include <vgui_controls/URLLabel.h>
#include <vgui_controls/TextEntry.h>
#include <vgui_controls/ImagePanel.h>
#include <vgui_controls/RichText.h>
#include <vgui_controls/Slider.h>
#include <vgui_controls/ComboBox.h>
#include <vgui_controls/ToggleButton.h>
#include <vgui_controls/ProgressBar.h>
#include <vgui_controls/ScrollBar.h>
#include <vgui_controls/ScrollBarSlider.h>

vgui::IEngineVGui *g_pEngineVGui;

#define RANDOM_LONG (*gEngfuncs.pfnRandomLong)

using namespace vgui;

void DEM_CreateFrame(void)
{
	CreateInterfaceFn EngineCreateInterface = g_pMetaHookAPI->GetEngineFactory();
	g_pEngineVGui = (vgui::IEngineVGui *)EngineCreateInterface(VENGINE_VGUI_VERSION, NULL);

	// add langauge file
	g_pVGuiLocalize->AddFile(g_pFullFileSystem, "resource/platform_%language%.txt");
	g_pVGuiLocalize->AddFile(g_pFullFileSystem, "resource/vgui_%language%.txt");

	VPANEL vRoot = g_pEngineVGui->GetPanel(PANEL_GAMEUIDLL);

	// base frame
	Frame *pFrame = new Frame(NULL, "BaseFrame");
	pFrame->SetParent(vRoot);
	pFrame->SetTitle(L"Test frame", false);
	pFrame->SetBounds(50, 50, 480, 350);
	pFrame->SetSizeable(false);
	pFrame->SetVisible(true);

	// enable button
	Button *pBtn1 = new Button(pFrame, "Btn01", L"Enable");
	pBtn1->SetBounds(10, 40, 100, 24);

	// disable button
	Button *pBtn2 = new Button(pFrame, "Btn02", L"Disable");
	pBtn2->SetBounds(10, 70, 100, 24);
	pBtn2->SetEnabled(false);

	// enable check button
	CheckButton *pCheckBtn1 = new CheckButton(pFrame, "CheckBtn01", "Enable");
	pCheckBtn1->SetBounds(118, 40, 100, 24);

	// disable check button
	CheckButton *pCheckBtn2 = new CheckButton(pFrame, "CheckBtn02", "Disable");
	pCheckBtn2->SetBounds(118, 70, 100, 24);
	pCheckBtn2->SetEnabled(false);

	// enable radio button
	RadioButton *pRadBtn1 = new RadioButton(pFrame, "RadBtn01", "Option 1");
	pRadBtn1->SetBounds(226, 40, 100, 24);

	// disable radio button
	RadioButton *pRadBtn2 = new RadioButton(pFrame, "RadBtn02", "Option 2");
	pRadBtn2->SetBounds(226, 70, 100, 24);
//	pRadBtn2->SetEnabled(false);

	// label
	Label *pLab = new Label(pFrame, "Lab", L"Hello!");
	pLab->SetBounds(334, 40, 100, 24);

	// url
	URLLabel *pUrl = new URLLabel(pFrame, "URLLabel", L"Google", "http://www.google.com/");
	pUrl->SetBounds(334, 70, 100, 24);

	// enable edit
	TextEntry *pEdit1 = new TextEntry(pFrame, "Edit01");
	pEdit1->SetBounds(10, 102, 100, 24);
	pEdit1->SetText(L"Enter text ...");

	// disable edit
	TextEntry *pEdit2 = new TextEntry(pFrame, "Edit02");
	pEdit2->SetBounds(10, 134, 100, 24);
	pEdit2->SetEnabled(false);
	pEdit2->SetText(L"Disabled");

	// multi line edit
	TextEntry *pEdit3 = new TextEntry(pFrame, "Edit03");
	pEdit3->SetBounds(118, 102, 208, 56);
	pEdit3->SetMultiline(true);
	pEdit3->SetText(L"Press Ctrl+Enter to newline\n");

	// image box
	ImagePanel *pImg = new ImagePanel(pFrame, "ImageBox");
	pImg->SetBounds(334, 102, 100, 56);
	pImg->SetImage("gfx/vgui/CS_Logo");

	// rich text box
	RichText *pRich = new RichText(pFrame, "RichTextBox");
	pRich->SetBounds(10, 166, 316, 88);
	for (int i = 0; i < 20; ++i)
	{
		Color clr( RANDOM_LONG(90,255), RANDOM_LONG(90,255), RANDOM_LONG(90,255), 255 );
		pRich->InsertColorChange(clr);
		char tLine[128];
		sprintf(tLine, "This is %d line !\n", i);
		pRich->InsertString(tLine);
	}

	// slider
	Slider *pSlider = new Slider(pFrame, "Slider");
	pSlider->SetBounds(334, 166, 100, 56);
	pSlider->SetRange(0, 12);
	pSlider->SetTickCaptions(L"low", L"high");

	// combo box (non edit)
	ComboBox *pComBox1 = new ComboBox(pFrame, "ComboBoxN", 5, false);
	pComBox1->SetBounds(10, 262, 100, 24);
	for (int i = 0; i < 20; ++i)
	{
		char tItem[128];
		sprintf(tItem, "Item %dx", i);
		pComBox1->AddItem(tItem, NULL);
	}
	pComBox1->ActivateItem(0);

	// combo box (non edit)
	ComboBox *pComBox2 = new ComboBox(pFrame, "ComboBoxE", 5, true);
	pComBox2->SetBounds(10, 294, 100, 24);
	for (int i = 0; i < 20; ++i)
	{
		char tItem[128];
		sprintf(tItem, "Item %dx", i);
		pComBox2->AddItem(tItem, NULL);
	}
	pComBox2->ActivateItem(0);

	// toggle button
	ToggleButton *pTogg = new ToggleButton(pFrame, "Togg", "Enable");
	pTogg->SetBounds(118, 262, 100, 24);

	// progress bar
	ProgressBar *pProgBar = new ProgressBar(pFrame, "ProgBar");
	pProgBar->SetBounds(226, 262, 208, 24);
	pProgBar->SetProgress(0.7f);

	// scroll bar
//	ScrollBar *pScroBar = new ScrollBar(pFrame, "ScroBar", false);
//	pScroBar->SetBounds(118, 294, 208, 24);
//	pScroBar->SetRange(0, 100);
//	pScroBar->SetValue(0);

}